﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ACP.DTO;

namespace ACP.Data
{
    public class MembershipUserRepository: Repository<aspnet_Users>
    {
        public static Guid GetuserGuidByUserName(string userName)
        {
            IRepository<aspnet_Users> usersRepository = new Repository<aspnet_Users>();
            Guid aspnetUserGuid;
            try
            {
                aspnetUserGuid = usersRepository.First(q => q.UserName == userName).UserId;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                usersRepository.Dispose();
            }
            return aspnetUserGuid;
        }
    }

    public class UserRepository : Repository<user>
    {
        public static user GetuserByGuid(Guid aspnetUserGuid)
        {
            IRepository<user> usersRepository = new Repository<user>();
            user userEntity;
            try
            {
                userEntity = usersRepository.First(q => q.guid == aspnetUserGuid);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                usersRepository.Dispose();
            }
            return userEntity;
        }

        public static List<user> GetAllUsers()
        {
            IRepository<user> usersRepository = new Repository<user>();
            List<user> userEntity;
            try
            {
                userEntity = usersRepository.GetAll().ToList();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                usersRepository.Dispose();
            }
            return userEntity;
        }

        public static void InsertUser(user currentUser)
        {
            Repository<user> userRepository = new Repository<user>();
            try
            {
                userRepository.Add(currentUser);
                userRepository.UnitOfWork.Commit();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                userRepository.Dispose();
            }
        }


    }
}
